package servlet;

import bean.Result;
import biz.OrderBiz;
import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "QueryOrderServlet", value = "/QueryOrderServlet.s")
public class QueryOrderServlet extends HttpServlet {
    private OrderBiz biz = new OrderBiz();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Result result;

        try {
            String status = request.getParameter("status");
            String begin = request.getParameter("begin");
            String end = request.getParameter("end");

            String currentPage = request.getParameter("currentPage");
            String pageSize = request.getParameter("pageSize");
            int page = Integer.valueOf(currentPage);
            int size = Integer.valueOf(pageSize);
            Map<String, Object> res = biz.query(status, begin, end, page, size);

            result = new Result(1, "查询成功!", res);

        }catch (Exception e){
            e.printStackTrace();
            result = new Result(0, "查询失败!", null);
        }
        String json = new Gson().toJson(result);
        response.getWriter().append(json);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
